from MasterMind import *
from random import choice

def start(size):
	global pines, password
	colors = ['blue','green','red','purple','orange','pink','lilac','brown','white','black']
	
	for color in colors:
		pines.append(Pine(color))
		
	pines_copy = pines[:-2]
		
	for position in xrange(size):
		pine = choice(pines_copy)
		pines_copy.pop(pines_copy.index(pine))
		password.add_pine(pine, position)

def show_game(press_ok=True):
	print 'Bloco |', block, '\n'
	if press_ok:
		print 'Dicas |', block.result_block(password), '\n'
		print 'Tentativa :', attempt, '\n'

	
def finished():
	return block == password
 
block = Block(5)
password = Block(5)
pines = []
start(5)
press_ok = False
attempt = 0
function_list = ['Adcionar', 'Retirar', 'Ok']
while True:
	show_game(press_ok)
	if finished():
		print 'You Win'
		break
	elif attempt == 12:
		print 'Game Over'
		break
	for i in xrange(len(function_list)):
		print '%s - %s  ' % (i+1, function_list[i]),
	function = input('Opcao: ')
	if function == 1:
		for i in xrange(len(pines[:-2])):
			print '%s - %s  ' % (i, pines[i])
		print
		choice_pine = input('Pino? ')
		choice_position = input('Posicao?')
		if not block.add_pine(pines[choice_pine], choice_position-1):
			print 'Ja existe um pino!'
	elif function == 2:
		remove = input('Qual a posicao do pino? ')
		block.remove_pine(remove+1)
	elif function == 3:
		if not block.contains(None):
			press_ok = True
			attempt += 1
			block = Block(5)
		else:
			print 'Bloco nao completado!'
	print